#include "blisp.h"

#define PROMPT "> "

/*
 * Destructive to-lower-case
 * Terminates at NUL byte
 */
static char *strtolower(char *s)
{
	char *p = s;
	while (*p++) *p = tolower(*p);
	return s;
}

/*
 * Only handles integers for now
 */
int main(int argc, char **argv)
{
	char buf[BUFSIZ];
	int n;
	Object oo;
	Object *o = &oo;

	blisp_init(); /* IMPORTANT */

	puts("BLISP (C) 2007 Ben Poplawski");

	while (1)
	{
		printf(PROMPT);
		if (fgets(buf, sizeof(buf), stdin) == NULL)
			break;
		strtolower(buf);
		if (strncmp(buf, "quit", 4) == 0)
			break;
		if (isdigit(buf[0]) || buf[0] == '-' || buf[0] == '+')
		{
			n = atoi(buf);
			o = Number_new(n);
			printf("%s\n", To_cstr(o));
		}
	}

	return EXIT_SUCCESS;
}
